package org.lcp.licai;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.text.method.DigitsKeyListener;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	TextView total, day;
	EditText benjin, shouyilv, tianshu;
	Button cal;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		init();

	}

	private void init() {

		total = (TextView) findViewById(R.id.total);
		day = (TextView) findViewById(R.id.day);
		
		benjin = (EditText) findViewById(R.id.benjin);
		shouyilv = (EditText) findViewById(R.id.shouyilv);
		tianshu = (EditText) findViewById(R.id.tianshu);
		
		benjin.setKeyListener(new DigitsKeyListener(false, true));
		shouyilv.setKeyListener(new DigitsKeyListener(false, true));
		tianshu.setKeyListener(new DigitsKeyListener(false, true));
		
		benjin.requestFocus();
		
		cal = (Button) findViewById(R.id.button1);
		cal.setClickable(true);
		cal.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				float benjinF, shouyilvF, tianshuF, totalF, dayF;
				// 本金
				benjinF = Float.parseFloat(benjin.getText().toString());
				// 收益率
				shouyilvF = Float.parseFloat(shouyilv.getText().toString());
				// 天数
				tianshuF = Float.parseFloat(tianshu.getText().toString());

				// 每天收益
				dayF = benjinF * shouyilvF / 36500;
				
				// 总收益
				totalF = dayF * tianshuF;

				total.setText(String.valueOf(totalF));
				day.setText(String.valueOf(dayF));
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
